export default {}
type Constructor<T = {}> = new (...args: any[]) => T;
// TypeScript 要求 Mixin 返回的类的构造函数必须是如下这种签名：
// constructor(...args: any[])

// 这个是用来约束类的实例方法的
type hasYueshu = Constructor<{ setPos: (x: number, y: number) => void }>


// 约束构造类型
type Constructor2<T = {}> = new (a: string, b: string) => T;
type hasYueshu2 = Constructor2<{ setPos: (x: number, y: number) => void, address: string }>


function cc<T extends hasYueshu2>(Base: T) {

}

class sdasda {
    a1: string
    b1: string
    address: string = ""

    constructor(a2: string, b: string) {
        this.a1 = a2
        this.b1 = b
    }

    setPos(x: number, y: number) {
        console.log(x + y)
    }
}

cc(sdasda)

// 定义混入函数
function CanJump<TBase extends hasYueshu>(Base: TBase) {
    return class extends Base {

        constructor(...args: any[]) {
            super(args);
        }

        jump() {
            console.log("I can jump");
        }

    };
}

// 基础类
class Animal {
    name = "Animal";
    address: string

    constructor(address: string) {
        this.address = address
    }

    setPos(x: number, y: number) {
        console.log(x + y)
    }
}

// 应用混入
const JumpingAnimal = CanJump(Animal);

const a = new JumpingAnimal("学报");
a.jump(); // I can jump
console.log(a.name); // Animal
